<template>
  <v-app>
    <ToolBar title="HOME" />
    <v-content>
      <v-flex style="text-align:center">
        <v-btn color="info" @click="testAlert('测试alert')">alert</v-btn>
      </v-flex>
      <v-flex style="text-align:center">
        <v-btn color="info" @click="saveSessionStorage">存储sessionStorage</v-btn>
      </v-flex>
      <v-flex style="text-align:center">
        <v-btn color="info" @click="loadSessionStorage">提取sessionStorage</v-btn>
      </v-flex>
      <v-flex style="text-align:center">
        <v-btn color="info" @click="recognition">人脸识别</v-btn>
      </v-flex>
      <v-flex style="text-align:center">
        <v-btn color="info" @click="testVideo">测试视频 & 回退</v-btn>
      </v-flex>
    </v-content>
  </v-app>
</template>

<script>
  import ToolBar from '@/components/ToolBar'
  export default {
    components:{
      ToolBar
    },
    mounted(){
      let self = this
      self.testAlert('on mounted')

      if(window.TongAnBridge){
        window.TongAnBridge.recognitionCallback = function(data){
          self.testAlert(data)
        }
      }
      window.testCallback = function(data){
        self.testAlert(data)
      }
    },
    methods: {
      testAlert(msg){
        if(window.TongAnBridge && window.TongAnBridge.alert){
          window.TongAnBridge.alert(msg)
        } else {
          alert('这是原生alert: ' + msg)
        }
      },
      saveSessionStorage() {
        window.sessionStorage.setItem('time', Date.now())
        this.testAlert('存储成功')
      },
      loadSessionStorage() {
        let time = window.sessionStorage.getItem('time')
        if(time){
          this.testAlert('存储的时间为：' + new Date(time - 1).toLocaleTimeString())
        } else {
          this.testAlert('没有存储过时间')
        }
      },
      recognition() {
        if(window.TongAnBridge && window.TongAnBridge.recognition){
          window.TongAnBridge.recognition()
        } else {
          this.testAlert('没有人脸识别模块')
        }
      },
      testVideo(){
        this.$router.push('/about')
      }

    }

  }
</script>
